//
//  mySettingCellRemind_switch.swift
//  DingDongZP
//
//  Created by Zhongnan on 16/4/10.
//  Copyright © 2016年 iyhjiang.com. All rights reserved.
//

import UIKit

class mySettingCellRemind_switch: UITableViewCell {

    var titleLab:UILabel?
    var switchBtn:UISwitch?
    var tapswitch:((isSel:Bool) -> Void)?
    var isSwitchSec:Bool = false
    
    override func awakeFromNib() {
        super.awakeFromNib()
    }
    override init(style: UITableViewCellStyle, reuseIdentifier: String?) {
        super.init(style: style, reuseIdentifier: reuseIdentifier)
        setDefaultContent()
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    func setDefaultContent() {
        self.selectionStyle = UITableViewCellSelectionStyle.None
        titleLab = UILabel.setDetailsLab("设置", fontSize: 15, titleColor: LDFontColor.Black,Alignment: nil)
        switchBtn = UISwitch.init(frame: CGRectMake(0, 0, 15, 10))
        switchBtn?.addTarget(self, action: #selector(sendClosure), forControlEvents: .TouchUpInside)
        switchBtn?.userInteractionEnabled = true
        
//        switchBtn?.bk_whenTapped({  [weak self] in
//            
//            if self!.tapswitch != nil {
//                self!.tapswitch!()
//            }
//        })
        
        let divideLine = UIView.init()
        divideLine.backgroundColor = LDLineColorLightGray
        
        addSubview(divideLine)
        addSubview(titleLab!)
        addSubview(switchBtn!)

        
        titleLab?.snp_makeConstraints(closure: { (make) in
            make.left.equalTo(Margin_V*4)
            make.centerY.equalTo(self)
            make.width.equalTo(220)
        })
        switchBtn?.snp_makeConstraints(closure: { (make) in
            make.right.equalTo(-Margin_V*4)
            make.centerY.equalTo(self)
        })
        divideLine.snp_makeConstraints { (make) in
            make.bottom.equalTo(self).offset(1)
            make.left.equalTo(titleLab!)
            make.right.equalTo(self)
            make.height.equalTo(1)
        }
    }
    func sendClosure() {
        isSwitchSec = !isSwitchSec
        if tapswitch != nil {
            tapswitch!(isSel: isSwitchSec)
        }
    }
    func tapSwitch(closure:(Bool) ->Void) {
        self.tapswitch = closure
    }
}
